package com.hc.app.batchcache;

import com.hc.app.cursor.dao.MyTableDao;
import com.hc.app.cursor.domain.entity.MyTable;
import com.hc.batchcache.AbstractRedisStringCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: huangcheng
 * @CreateTime: 2024-12-09  09:45
 * @Description:
 * @Version: 1.0
 */
@Service
public class RedisCache extends AbstractRedisStringCache<Integer, MyTable> {
    @Autowired
    private MyTableDao tableDao;
    @Override
    protected String getKey(Integer req) {
        return String.valueOf(req);
    }

    @Override
    protected Long getExpireSeconds() {
        return 30L;
    }

    @Override
    protected Map<Integer, MyTable> load(List<Integer> req) {
        List<MyTable> myTableList = tableDao.listByTableIds(req);
        return myTableList.stream().collect(Collectors.toMap(MyTable::getId, Function.identity()));
    }
}
